<script>
	export default {
		onLaunch: function() {
			console.log('App Launch')
			uni.getSystemInfo({
				success: (res) => {
					this.globalData.statusBarHeight = res.statusBarHeight; // 状态栏高度
					this.globalData.navBarHeight = res.platform === 'android' ? 48 :
						44; // 导航栏高度（安卓48px，iOS44px）:cite[3]:cite[5]
				}
			})
			// #ifdef APP-PLUS
			//this.setupAppLifecycle();
			// #endif
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		globalData: {
			apiUrl: 'https://4pay.dt12.cfd'
		},
		methods: {
			/* setupAppLifecycle() {
				let lastResumeTime = 0;
				const minRefreshInterval = 30000; // 30秒内不重复刷新

				plus.global.addEventListener('resume', async () => {
					const now = Date.now();

					// 避免频繁触发
					if (now - lastResumeTime < minRefreshInterval) return;
					lastResumeTime = now;

					// 检查网络状态
					const networkType = await this.checkNetwork();
					if (networkType === 'none') return;

					// 检查 token 有效性
					if (!util.isValid()) {
						try {
							const success = await util.refresh();
							if (!success) {
								util.toLogin();
							}
						} catch (error) {
							console.error('Token refresh on resume failed:', error);
						}
					}
				});
			}, */
			checkNetwork() {
				return new Promise(resolve => {
					uni.getNetworkType({
						success: res => resolve(res.networkType),
						fail: () => resolve('unknown')
					});
				});
			}
		}
	}
</script>

<style>
	/*每个页面公共css */
	@import url("./publicUI/publicUI.css");
</style>